package com.hbpu.encap.IO;

import java.io.*;

public class BufferedCopy02 {
    public static void main(String[] args) {
        String srcPath = "E:\\预告封面.png";
        String copyPath = "E:\\copy.png";
        BufferedInputStream bis = null;
        BufferedOutputStream bos = null;
        int read = 0;
        try {
            bis = new BufferedInputStream(new FileInputStream(srcPath));
            bos = new BufferedOutputStream(new FileOutputStream(copyPath));
            byte[] bytes = new byte[1024];
            while ((read = bis.read(bytes)) != -1) {
                bos.write(bytes, 0, read);
            }

        } catch (IOException e) {
            System.out.println("写入时出现错误：" + e.getMessage());
        } finally {
            try {
                if (bis != null) {
                    bis.close();
                }
                if (bos != null) {
                    bos.close();
                }
                System.out.println("拷贝成功！");
            } catch (IOException e) {
                System.out.println("拷贝失败！");
            }
        }
    }
}
